***** RUN DO_MASTER.do ***** do "$Do_files\DO_MASTER.do"

global program "OA_TableB39"
cap log close
cap log using "$Log_files\log_$program$today", replace

**** REPLICATION OF TABLE B.3.9 ****

clear all
set mem 2g
set more off

// Import data

use $Data\data_newspapers, clear

// Newspaper level

estpost tabstat hq00_case_F_p hq00_case_N_p hqcSR_F_N hqcDEV_F_N, by(newspaper_str) s(mean) nototal //

// Table HQC (LR) and HQC (DEV) - Paper

estout using "$Results\\$program.tex", replace style(tex) type label ///
	cells("hq00_case_F_p(label($ \mathtt{F} $) fmt(0)) hq00_case_N_p(label($ \mathtt{CH} $) fmt(0)) hqcSR_F_N(label($ \mathtt{CPD}^{\mathtt{HQ}}_{j} $) fmt(2)) hqcDEV_F_N(label($ \mathtt{CPD}^{\mathtt{HQ}}_{j} - \overline{\mathtt{CPD}}^{\mathtt{HQ}}_{j} $) fmt(2))") ///
	varlabels(`e(labels)') ///
	mlabels(, none) ///
	title("News and voting: Identifying variations") ///
	prehead("\begin{table}[!h]" ///
	"\centering" ///
	"%\resizebox {0.75\textwidth}{!}{%" ///
	"\begin{threeparttable}" ///
	"\begin{footnotesize}" ///
	"\caption{\small{@title}\label{$program}}" ///
	"\begin{tabular*}{\columnwidth}{@{\extracolsep{\stretch{1}}}l*{4}{c}@{}}" ///
	"\hline" "\hline" ///
	"\\" ///
	"			& \multicolumn{2}{c}{} & \multicolumn{1}{c}{Crime Propensity} & \multicolumn{1}{c}{Crime Propensity} 	\\" /// 
	"			& \multicolumn{2}{c}{Crimes (\#)} & \multicolumn{1}{c}{Differential} & \multicolumn{1}{c}{Differential} \\" /// 
	"Newspaper ($ j$)	& \multicolumn{2}{c}{Short-Run} & \multicolumn{1}{c}{Short-Run}	& \multicolumn{1}{c}{Deviation}	\\" /// 	
	"\cmidrule{2-3} \cmidrule{4-4} \cmidrule{5-5}") ///
	posthead("\hline" ///
	"\\") ///
	prefoot("") ///
	postfoot("\\")

// Average newspaper
	
g x=1
label define x 	1	"Average newspaper"
la val x x 

collapse (mean) hq00_case_F_p hq00_case_N_p hqcSR_F_N hqcDEV_F_N, by(x)

estpost tabstat hq00_case_F_p hq00_case_N_p hqcSR_F_N hqcDEV_F_N, by(x) s(mean) nototal //

// Paper

estout using "$Results\\$program.tex", append style(tex) type label ///
	cells("hq00_case_F_p(label($ \mathtt{F} $) fmt(2)) hq00_case_N_p(label($ \mathtt{CH} $) fmt(2)) hqcSR_F_N(label($ \mathtt{CPD}^{\mathtt{HQ}}_{j} $) fmt(2)) hqcDEV_F_N(label($ \mathtt{CPD}^{\mathtt{HQ}}_{j} - \overline{\mathtt{CPD}}^{\mathtt{HQ}}_{j} $) fmt(2))") ///
	varlabels(`e(labels)') ///
	collabels(none) ///
	mlabels(, none) ///
	prehead("") ///
	posthead("\hline" ///
	"") ///
	prefoot("") ///
	postfoot("\hline" "\hline" ///
	"\end{tabular*}" ///
	"\end{footnotesize}" ///
	"\begin{tablenotes}[normal,flushleft]" ///
	"\begin{scriptsize}" ///
	"\item \emph{Notes}:" ///
	"Population and crime calculated at newspaper level, i.e. summing local populations and local crimes in municipalities hosting a headquarter. " ///
	"Crime data comes from the Swiss Statistical Office (FSO). " ///
	"The crime propensity differential short run, $\mathtt{CPD}^{\mathtt{HQ}}_{j} \equiv \frac{\# \mathtt{crime}^{\mathtt{HQ}}_{\mathtt{F}}}  {\mathtt{pop}^{\mathtt{HQ}}_\mathtt{F}} - \frac{\# \mathtt{crime}^{\mathtt{HQ}}_{\mathtt{CH}}}  {\mathtt{pop}^{\mathtt{HQ}}_{\mathtt{CH}}}$, " ///
	"is computed over the period Jan 1, 2009 to Nov 30, 2009. " ///
	"$\overline{\mathtt{CPD}}^{\mathtt{HQ}}_{j}$ is calculated over the period Dec 1, 2009 to Dec 31, 2013. " ///
	" " ///
	"\end{scriptsize}" ///
	"\end{tablenotes}" ///
	"\end{threeparttable}%}" ///
	"\end{table}")

cap log close
